package accel.movement;

import java.util.LinkedList;
import java.util.ListIterator;

import accel.movements.Attack;
import accel.dataholders.Character;

public abstract class AttackSet {

	public static final AttackSet [] attackCollection = {new StandardAttackSet(null)}; //jak coś dodajesz, updatuj też funkcję poniżej
	
	public static int getSetId(AttackSet set)
	{
		if (set instanceof StandardAttackSet)
			return 0;
		return -1;
	}
	
	protected Attack [] attacks;
	
	public Attack [] getAll()
	{
		return attacks;
	}
	
	public abstract AttackSet generateForParent(Character c);
	
	
	public Attack process(LinkedList<Movement3D> movs) {
		ListIterator <Movement3D>i1 = movs.listIterator();
		ListIterator <Movement3D> i2;
		int i,j,len;
		Movement3D tmp;
		while (i1.hasNext())
		{
			tmp = i1.next();
			for (i = 0; i<attacks.length; i++)
			{
				i2 = null;
				len = attacks[i].getPattern().length;
				for (j = 0; j<len; j++)
				{
					if (i2 == null)
					{
						if (!attacks[i].getPattern()[j].equals(tmp))
							break;
						i2 = movs.listIterator(i1.nextIndex());
					}
					else
					{
						if (i2.hasNext())
						{
							if (!attacks[i].getPattern()[j].equals(i2.next()))
								break;
						}
						else
							break;
					}
				}
				if (j == len)
				{
					int l = movs.size() - i2.nextIndex();
					while (movs.size() > l)
						movs.removeFirst();
					return attacks[i];
				}
			}
		}
		return null;
	}
}
